# Runtime library files management
# 这个文件负责管理runtime/python目录下的语言库文件

# 创建library目录
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/pylib)

# 获取python目录下的所有文件
file(GLOB PYTHON_FILES "${CMAKE_CURRENT_SOURCE_DIR}/python/*")

# 为每个python文件创建拷贝命令
foreach(PYTHON_FILE ${PYTHON_FILES})
    if(EXISTS ${PYTHON_FILE})
        get_filename_component(FILENAME ${PYTHON_FILE} NAME)
        add_custom_command(
            OUTPUT ${CMAKE_BINARY_DIR}/pylib/${FILENAME}
            COMMAND ${CMAKE_COMMAND} -E copy_if_different
            ${PYTHON_FILE}
            ${CMAKE_BINARY_DIR}/pylib/${FILENAME}
            DEPENDS ${PYTHON_FILE}
            COMMENT "Copying python library file: ${FILENAME}"
        )
        list(APPEND PYTHON_COPY_TARGETS ${CMAKE_BINARY_DIR}/pylib/${FILENAME})
    endif()
endforeach()

# 创建自定义目标来管理所有python文件拷贝操作
add_custom_target(python_libs ALL DEPENDS ${PYTHON_COPY_TARGETS})

# 获取stdlib目录下的所有.gs文件
file(GLOB GS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/stdlib/*.gs")

# 为每个.gs文件创建拷贝命令
foreach(GS_FILE ${GS_FILES})
    if(EXISTS ${GS_FILE})
        get_filename_component(GS_FILENAME ${GS_FILE} NAME)
        add_custom_command(
            OUTPUT ${CMAKE_BINARY_DIR}/libs/${GS_FILENAME}
            COMMAND ${CMAKE_COMMAND} -E copy_if_different
            ${GS_FILE}
            ${CMAKE_BINARY_DIR}/libs/${GS_FILENAME}
            DEPENDS ${GS_FILE}
            COMMENT "Copying stdlib gs file: ${GS_FILENAME}"
        )
        list(APPEND GS_COPY_TARGETS ${CMAKE_BINARY_DIR}/libs/${GS_FILENAME})
    endif()
endforeach()

# 创建自定义目标来管理所有.gs文件拷贝操作
add_custom_target(gs_libs ALL DEPENDS ${GS_COPY_TARGETS})

